| Conditions | 1 |
| Paths | 2304 |
| Total Lines | 165 |
| Code Lines | 92 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | /*! |
||
| 75 | function () { |
||
| 76 | function Tab(element) { |
||
| 77 | this._element = element; |
||
| 78 | } // Getters |
||
| 79 | |||
| 80 | |||
| 81 | var _proto = Tab.prototype; |
||
| 82 | |||
| 83 | // Public |
||
| 84 | _proto.show = function show() { |
||
| 85 | var _this = this; |
||
| 86 | |||
| 87 | if (this._element.parentNode && this._element.parentNode.nodeType === Node.ELEMENT_NODE && $(this._element).hasClass(ClassName.ACTIVE) || $(this._element).hasClass(ClassName.DISABLED)) { |
||
| 88 | return; |
||
| 89 | } |
||
| 90 | |||
| 91 | var target; |
||
| 92 | var previous; |
||
| 93 | var listElement = $(this._element).closest(Selector.NAV_LIST_GROUP)[0]; |
||
| 94 | var selector = Util.getSelectorFromElement(this._element); |
||
| 95 | |||
| 96 | if (listElement) { |
||
| 97 | var itemSelector = listElement.nodeName === 'UL' || listElement.nodeName === 'OL' ? Selector.ACTIVE_UL : Selector.ACTIVE; |
||
| 98 | previous = $.makeArray($(listElement).find(itemSelector)); |
||
| 99 | previous = previous[previous.length - 1]; |
||
| 100 | } |
||
| 101 | |||
| 102 | var hideEvent = $.Event(Event.HIDE, { |
||
| 103 | relatedTarget: this._element |
||
| 104 | }); |
||
| 105 | var showEvent = $.Event(Event.SHOW, { |
||
| 106 | relatedTarget: previous |
||
| 107 | }); |
||
| 108 | |||
| 109 | if (previous) { |
||
| 110 | $(previous).trigger(hideEvent); |
||
| 111 | } |
||
| 112 | |||
| 113 | $(this._element).trigger(showEvent); |
||
| 114 | |||
| 115 | if (showEvent.isDefaultPrevented() || hideEvent.isDefaultPrevented()) { |
||
| 116 | return; |
||
| 117 | } |
||
| 118 | |||
| 119 | if (selector) { |
||
| 120 | target = document.querySelector(selector); |
||
| 121 | } |
||
| 122 | |||
| 123 | this._activate(this._element, listElement); |
||
| 124 | |||
| 125 | var complete = function complete() { |
||
| 126 | var hiddenEvent = $.Event(Event.HIDDEN, { |
||
| 127 | relatedTarget: _this._element |
||
| 128 | }); |
||
| 129 | var shownEvent = $.Event(Event.SHOWN, { |
||
| 130 | relatedTarget: previous |
||
| 131 | }); |
||
| 132 | $(previous).trigger(hiddenEvent); |
||
| 133 | $(_this._element).trigger(shownEvent); |
||
| 134 | }; |
||
| 135 | |||
| 136 | if (target) { |
||
| 137 | this._activate(target, target.parentNode, complete); |
||
| 138 | } else { |
||
| 139 | complete(); |
||
| 140 | } |
||
| 141 | }; |
||
| 142 | |||
| 143 | _proto.dispose = function dispose() { |
||
| 144 | $.removeData(this._element, DATA_KEY); |
||
| 145 | this._element = null; |
||
| 146 | } // Private |
||
| 147 | ; |
||
| 148 | |||
| 149 | _proto._activate = function _activate(element, container, callback) { |
||
| 150 | var _this2 = this; |
||
| 151 | |||
| 152 | var activeElements = container && (container.nodeName === 'UL' || container.nodeName === 'OL') ? $(container).find(Selector.ACTIVE_UL) : $(container).children(Selector.ACTIVE); |
||
| 153 | var active = activeElements[0]; |
||
| 154 | var isTransitioning = callback && active && $(active).hasClass(ClassName.FADE); |
||
| 155 | |||
| 156 | var complete = function complete() { |
||
| 157 | return _this2._transitionComplete(element, active, callback); |
||
| 158 | }; |
||
| 159 | |||
| 160 | if (active && isTransitioning) { |
||
| 161 | var transitionDuration = Util.getTransitionDurationFromElement(active); |
||
| 162 | $(active).removeClass(ClassName.SHOW).one(Util.TRANSITION_END, complete).emulateTransitionEnd(transitionDuration); |
||
| 163 | } else { |
||
| 164 | complete(); |
||
| 165 | } |
||
| 166 | }; |
||
| 167 | |||
| 168 | _proto._transitionComplete = function _transitionComplete(element, active, callback) { |
||
| 169 | if (active) { |
||
| 170 | $(active).removeClass(ClassName.ACTIVE); |
||
| 171 | var dropdownChild = $(active.parentNode).find(Selector.DROPDOWN_ACTIVE_CHILD)[0]; |
||
| 172 | |||
| 173 | if (dropdownChild) { |
||
| 174 | $(dropdownChild).removeClass(ClassName.ACTIVE); |
||
| 175 | } |
||
| 176 | |||
| 177 | if (active.getAttribute('role') === 'tab') { |
||
| 178 | active.setAttribute('aria-selected', false); |
||
| 179 | } |
||
| 180 | } |
||
| 181 | |||
| 182 | $(element).addClass(ClassName.ACTIVE); |
||
| 183 | |||
| 184 | if (element.getAttribute('role') === 'tab') { |
||
| 185 | element.setAttribute('aria-selected', true); |
||
| 186 | } |
||
| 187 | |||
| 188 | Util.reflow(element); |
||
| 189 | |||
| 190 | if (element.classList.contains(ClassName.FADE)) { |
||
| 191 | element.classList.add(ClassName.SHOW); |
||
| 192 | } |
||
| 193 | |||
| 194 | if (element.parentNode && $(element.parentNode).hasClass(ClassName.DROPDOWN_MENU)) { |
||
| 195 | var dropdownElement = $(element).closest(Selector.DROPDOWN)[0]; |
||
| 196 | |||
| 197 | if (dropdownElement) { |
||
| 198 | var dropdownToggleList = [].slice.call(dropdownElement.querySelectorAll(Selector.DROPDOWN_TOGGLE)); |
||
| 199 | $(dropdownToggleList).addClass(ClassName.ACTIVE); |
||
| 200 | } |
||
| 201 | |||
| 202 | element.setAttribute('aria-expanded', true); |
||
| 203 | } |
||
| 204 | |||
| 205 | if (callback) { |
||
| 206 | callback(); |
||
| 207 | } |
||
| 208 | } // Static |
||
| 209 | ; |
||
| 210 | |||
| 211 | Tab._jQueryInterface = function _jQueryInterface(config) { |
||
| 212 | return this.each(function () { |
||
| 213 | var $this = $(this); |
||
| 214 | var data = $this.data(DATA_KEY); |
||
| 215 | |||
| 216 | if (!data) { |
||
| 217 | data = new Tab(this); |
||
| 218 | $this.data(DATA_KEY, data); |
||
| 219 | } |
||
| 220 | |||
| 221 | if (typeof config === 'string') { |
||
| 222 | if (typeof data[config] === 'undefined') { |
||
| 223 | throw new TypeError("No method named \"" + config + "\""); |
||
| 224 | } |
||
| 225 | |||
| 226 | data[config](); |
||
| 227 | } |
||
| 228 | }); |
||
| 229 | }; |
||
| 230 | |||
| 231 | _createClass(Tab, null, [{ |
||
| 232 | key: "VERSION", |
||
| 233 | get: function get() { |
||
| 234 | return VERSION; |
||
| 235 | } |
||
| 236 | }]); |
||
| 237 | |||
| 238 | return Tab; |
||
| 239 | }(); |
||
| 240 | /** |
||
| 270 |